package com.erlang.jpa.pojo;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.HashSet;
import java.util.Set;

/**
 * 客户的实体类
 *
 * @Author ZGQ
 */
@Entity // 声明实体类
@Table(name = "cst_customer") //建立实体类和表的映射关系
public class Customer {

  @Id //声明当前私有属性为主键
  @GeneratedValue(strategy = GenerationType.IDENTITY) //配置主键的生成策略
  @Column(name = "cust_id") // 指定和表中的cust_id字段的映射关系
  private Long custId;
  @Column(name = "cust_name")
  private String custName;
  @Column(name = "cust_source")
  private String custSource;
  @Column(name = "cust_industry")
  private String custIndustry;
  @Column(name = "cust_level")
  private String custLevel;
  @Column(name = "cust_address")
  private String custAddress;
  @Column(name = "cust_phone")
  private String custPhone;

  /**
   * 在客户对象的@OneToMany注解中添加fetch属性
   * 		FetchType.EAGER	：立即加载
   * 		FetchType.LAZY	：延迟加载
   */
  /**
   * cascade:配置级联操作
   * 		CascadeType.MERGE	级联更新
   * 		CascadeType.PERSIST	级联保存：
   * 		CascadeType.REFRESH 级联刷新：
   * 		CascadeType.REMOVE	级联删除：
   * 		CascadeType.ALL		包含所有
   */
  /**
   * 放弃外键维护权的配置将如下配置改为
   */
  //配置客户和联系人的一对多关系
  //@OneToMany(targetEntity=LinkMan.class)
  //@JoinColumn(name="lkm_cust_id",referencedColumnName="cust_id")
  @OneToMany(mappedBy="customer", cascade = CascadeType.ALL, fetch= FetchType.LAZY)
  private Set<LinkMan> linkMans = new HashSet<LinkMan>(0);

  public Long getCustId() {
    return custId;
  }

  public void setCustId(Long custId) {
    this.custId = custId;
  }

  public String getCustName() {
    return custName;
  }

  public void setCustName(String custName) {
    this.custName = custName;
  }

  public String getCustSource() {
    return custSource;
  }

  public void setCustSource(String custSource) {
    this.custSource = custSource;
  }

  public String getCustIndustry() {
    return custIndustry;
  }

  public void setCustIndustry(String custIndustry) {
    this.custIndustry = custIndustry;
  }

  public String getCustLevel() {
    return custLevel;
  }

  public void setCustLevel(String custLevel) {
    this.custLevel = custLevel;
  }

  public String getCustAddress() {
    return custAddress;
  }

  public void setCustAddress(String custAddress) {
    this.custAddress = custAddress;
  }

  public String getCustPhone() {
    return custPhone;
  }

  public void setCustPhone(String custPhone) {
    this.custPhone = custPhone;
  }

  public Set<LinkMan> getLinkMans() {
    return linkMans;
  }

  public void setLinkMans(Set<LinkMan> linkMans) {
    this.linkMans = linkMans;
  }

  @Override
  public String toString() {
    return "Customer{" +
        "custId=" + custId +
        ", custName='" + custName + '\'' +
        ", custSource='" + custSource + '\'' +
        ", custIndustry='" + custIndustry + '\'' +
        ", custLevel='" + custLevel + '\'' +
        ", custAddress='" + custAddress + '\'' +
        ", custPhone='" + custPhone + '\'' +
        ", linkMans=" + linkMans +
        '}';
  }
}
